package it.softphone.cmc.server.security;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;

public class MultiTenantFormAuthenticationFilter extends FormAuthenticationFilter {

	public MultiTenantFormAuthenticationFilter() {
	}

	private String getTenant( ServletRequest request ) {
		String tenant = request.getParameter("tenant");
/*		
		if( tenant == null ) {
			 TenantService service = ApplicationConfig.getBean(TenantService.class);
			 tenant = service.getSystemTenant();
		}
*/		
		return tenant;
	}
	@Override
	protected final AuthenticationToken createToken(String username, String password,	ServletRequest request, ServletResponse response) {
		boolean rememberMe = isRememberMe(request);
		String host = getHost(request);
		String tenant = getTenant(request);
		
		return new MultiTenantAuthenticationToken(username, password, rememberMe, host, tenant);
	}


}
